package cc.mrbird.febs.order.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wuwenze.poi.ExcelKit;

import cc.mrbird.febs.common.annotation.ControllerEndpoint;
import cc.mrbird.febs.common.controller.BaseController;
import cc.mrbird.febs.common.entity.FebsConstant;
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.common.entity.QueryRequest;
import cc.mrbird.febs.common.utils.FebsUtil;
import cc.mrbird.febs.order.entity.OrderPay;
import cc.mrbird.febs.order.service.IOrderPayService;
import lombok.RequiredArgsConstructor;

/**
 * 订单支付表 Controller
 *
 * @author Lord
 * @date 2020-06-06 17:07:09
 */
@Validated
@Controller
@RequiredArgsConstructor
public class OrderPayController extends BaseController {

    private final IOrderPayService orderPayService;

    @GetMapping(FebsConstant.VIEW_PREFIX + "orderPay")
    public String orderPayIndex() {
        return FebsUtil.view("orderPay/orderPay");
    }

    @GetMapping("orderPay")
    @ResponseBody
    @RequiresPermissions("orderPay:list")
    public FebsResponse getAllOrderPays(OrderPay orderPay) {
        return new FebsResponse().success().data(orderPayService.findOrderPays(orderPay));
    }

    @GetMapping("orderPay/list")
    @ResponseBody
    @RequiresPermissions("orderPay:list")
    public FebsResponse orderPayList(QueryRequest request, OrderPay orderPay) {
        Map<String, Object> dataTable = getDataTable(this.orderPayService.findOrderPays(request, orderPay));
        return new FebsResponse().success().data(dataTable);
    }

    @ControllerEndpoint(operation = "新增OrderPay", exceptionMessage = "新增OrderPay失败")
    @PostMapping("orderPay")
    @ResponseBody
    @RequiresPermissions("orderPay:add")
    public FebsResponse addOrderPay(@Valid OrderPay orderPay) {
        this.orderPayService.createOrderPay(orderPay);
        return new FebsResponse().success();
    }

    @ControllerEndpoint(operation = "删除OrderPay", exceptionMessage = "删除OrderPay失败")
    @GetMapping("orderPay/delete")
    @ResponseBody
    @RequiresPermissions("orderPay:delete")
    public FebsResponse deleteOrderPay(OrderPay orderPay) {
        this.orderPayService.deleteOrderPay(orderPay);
        return new FebsResponse().success();
    }

    @ControllerEndpoint(operation = "修改OrderPay", exceptionMessage = "修改OrderPay失败")
    @PostMapping("orderPay/update")
    @ResponseBody
    @RequiresPermissions("orderPay:update")
    public FebsResponse updateOrderPay(OrderPay orderPay) {
        this.orderPayService.updateOrderPay(orderPay);
        return new FebsResponse().success();
    }

    @ControllerEndpoint(operation = "修改OrderPay", exceptionMessage = "导出Excel失败")
    @PostMapping("orderPay/excel")
    @ResponseBody
    @RequiresPermissions("orderPay:export")
    public void export(QueryRequest queryRequest, OrderPay orderPay, HttpServletResponse response) {
        List<OrderPay> orderPays = this.orderPayService.findOrderPays(queryRequest, orderPay).getRecords();
        ExcelKit.$Export(OrderPay.class, response).downXlsx(orderPays, false);
    }
}
